package com.sptpc.demo1.controller;

import com.sptpc.demo1.model.Book;
import com.sptpc.demo1.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class RouterController {

    @Autowired
    IBookService bookService;

    //界面管理
    @GetMapping("/")
    public String Login(){
        return "manage/login";
    }
    @GetMapping("manage/index")
    public String Index(){
        return "manage/index";
    }
    @GetMapping("manage/welcome")
    public String welcome(){
        return "manage/welcome";
    }





    @GetMapping("/menu/book")
    public String bookindex(){
        return "book/index";
    }
    @GetMapping("/book/addform")
    public String bookaddForm(){
        return "book/add";
    }
    @GetMapping("/book/updateform")
    public ModelAndView bookupdateform(@RequestParam Integer id){
        ModelAndView modelAndView=new ModelAndView("book/edit");
        //从数据库通过id查询出对应的学生信息
        Book book=bookService.getbookById(id);
        modelAndView.addObject("data",book);
        return modelAndView;
    }
}
